import {get, post, Patch, Delete} from './axios';
import vuex from '@/store/index.js'
/*
  本地地址
  http://localhost:8888
  线上地址
  http://121.5.128.248:8888
*/
const online = 'http://121.5.128.248:8888';

export const ajax = {
  // 首页数据
  homeData: () => get('rock.api.mobile.index.page'),
  // 产品类别
  productCategory: () => get("rock.api.mobile.category.page"),
  // 产品列表
  productList: (params) => get("rock.api.mobile.goods.page", params),
  // 产品详细信息
  detailsData: (data) => post("ecapi.product.get", data),
  // 详情图
  detailsImg: (data) => post("ecapi.article.getArticleByName", data),
  // 加入购物车
  addShoppingCart: (data, headers) => post("ecapi.cart.add", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 登录
  login: (data) => post("ecapi.auth.signin", data),
  // 手机号是否注册
  verifyPhone: (data) => post("ecapi.auth.mobile.verify", data),
  // 发送手机验证码
  verifyCode: (data) => post("ecapi.auth.mobile.send", data),
  // 注册
  register: (data) => post("ecapi.auth.mobile.signup", data),
  // 忘记密码 检查电话注册
  checkPhoneRegister: (data) => post("ecapi.auth.mobile.checkPhoneRegister", data),
  // 忘记密码 修改密码
  resetPassword: (data) => post("ecapi.auth.mobile.reset", data),
  // 购物车
  shoppingCart: (headers) => post("ecapi.cart.get", {}, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 购物车数据更新
  upShoppingCart: (data, headers) => post("ecapi.cart.update", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 购物车数据删除
  delShoppingCart: (data, headers) => post("ecapi.cart.delete", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 我的  徽标
  getBadge: (headers) => post("ecapi.order.subtotal", {is_from: "mini"}, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 订单列表
  orderList: (data, headers) => post("ecapi.order.list", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 取消订单
  cancelOrder: (data, headers) => post("ecapi.order.cancel", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 订单详情
  orderDetails: (data, headers) => post("ecapi.order.get", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 确认订单 价格
  orderPrice: (data, headers) => post("ecapi.order.price", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 提交订单
  submitOrders: (data, headers) => post("ecapi.product.purchase", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 提交购物车订单
  submitCartOrder: (data, headers) => post("ecapi.cart.checkout", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 售后列表
  afterSalesList: (headers) => post("ecapi.orderback.getList", {}, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 全国全部地址
  allAddress: () => post("ecapi.region.list", {}),
  // 我的地址
  myAddress: (headers) => post("ecapi.consignee.list", {}, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 修改地址
  upAddress: (data, headers) => post("ecapi.consignee.update", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 删除地址
  delAddress: (data, headers) => post("ecapi.consignee.delete", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 添加地址
  addAddress: (data, headers) => post("ecapi.consignee.add", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 优惠券 列表
  couponList: (data, headers) => post("ecapi.cashgift.list", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 添加优惠券
  addCoupon: (data, headers) => post("ecapi.cashgift.add", data, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),
  // 奖品列表
  prizeList: (headers) => get("rock.api.lottery.my.prize", {}, {
    ...headers,
    "X-ECAPI-Authorization": vuex.getters.token
  }),

  // 查找点赞
  getLike: (params) => get(`${online}/like`, params),
  // 添加点赞
  addLike: (data) => post(`${online}/like`, data),
  // 取消点赞
  delLike: (id) => Delete(`${online}/like/` + id),

  // 查找收藏
  getCollect: (params) => get(`${online}/collect`, params),
  // 添加收藏
  addCollect: (data) => post(`${online}/collect`, data),
  // 取消收藏
  delCollect: (id) => Delete(`${online}/collect/` + id),

  // 查询评论
  getContent: (params) => get(`${online}/comment`, params),
  // 添加评论
  addContent: (data) => post(`${online}/comment`, data),
}

